﻿namespace AnyOffice.WebControls
{
    using System;
    using System.Web;
    using System.Web.UI.WebControls.WebParts;

    public class PortalSqlPersonalizationProvider : SqlPersonalizationProvider
    {
        public override PersonalizationScope DetermineInitialScope(WebPartManager webPartManager, PersonalizationState loadedState)
        {
            return webPartManager.Personalization.InitialScope;
        }

        private string GetLoginUserId()
        {
            return HttpContext.Current.Session["userid"].ToString();
        }

        protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob)
        {
            base.LoadPersonalizationBlobs(webPartManager, path, this.GetLoginUserId(), ref sharedDataBlob, ref userDataBlob);
        }

        protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName)
        {
            base.ResetPersonalizationBlob(webPartManager, path, this.GetLoginUserId());
        }

        protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob)
        {
            base.SavePersonalizationBlob(webPartManager, path, this.GetLoginUserId(), dataBlob);
        }
    }
}

